package com.javaweb.dao.impl;

import com.javaweb.dao.TagDao;
import com.javaweb.model.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

/**
 * @desc:
 * @author: Shoko
 * @date: 2024/10/22
 */
@Repository
public class TagDaoImpl implements TagDao {
    @Autowired
    private JdbcTemplate  jdbcTemplate;
    //  （14）新增标签：int insert(Tag tag)
    @Override
    public int insert(Tag tag) {
        String sql="insert into tb_tag(name,create_time,update_time) values(?,?,?)";
        Object[] args=new Object[]{tag.getName(),tag.getCreateTime(),tag.getUpdateTime()};
        return jdbcTemplate.update(sql,args)>0?1:0;
    }
    //    (15) 新增文章标签：int insertArticleTag(Integer articleId, Integer tagId)
    @Override
    public int insertArticleTag(Integer articleId, Integer tags) {
        String sql="insert into tb_article_tag(article_id,tag_id) values(?,?)";
        Object[] args=new Object[]{articleId,tags};
        return jdbcTemplate.update(sql,args)>0?1:0;
    }
}
